package com.hu.zhcc.shiro.controller.HealthIntervention;

import com.hu.zhcc.common.entity.Page;
import com.hu.zhcc.shiro.entity.bo.HealthIntervention.Followupdiary;
import com.hu.zhcc.shiro.service.HealthIntervention.FollowupdiaryService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@CrossOrigin
@RestController
@RequestMapping("/upDiary")
public class FollowUpDiaryController {
    @Autowired
    private FollowupdiaryService followupdiaryService;
//初始查询
    @GetMapping("")
    public ResponseEntity<Page<Followupdiary>> findFollowUpDiary(@RequestParam(required = false) String diaryPerson,int offset, int limit){
        Map map = new HashMap();
        if (!StringUtils.isBlank(diaryPerson)){
            map.put("diaryPerson",diaryPerson);
        }
        Page<Followupdiary> byPageList = followupdiaryService.findByPageList(map,offset, limit);
        return ResponseEntity.ok(byPageList);
    }

    //删除
    @DeleteMapping("/{id}")
    public int removeDiary(@PathVariable("id") int id){
        return followupdiaryService.deleteByPrimaryKey(id);
    }
    //根据编号查询需要修改的信息
    @GetMapping("/{id}")
    public ResponseEntity<Followupdiary> getById(@PathVariable("id") int id) {
        Followupdiary followupdiary = followupdiaryService.selectByPrimaryKey(id);
        System.out.println(followupdiary);
        return ResponseEntity.ok(followupdiary);
    }

    //修改
    @PutMapping("")
    public int updateDiary(@RequestBody  Followupdiary followupdiary){
        return followupdiaryService.updateByPrimaryKeySelective(followupdiary);
    }

    //添加
    @PostMapping("")
    public int addDiary(@RequestBody Followupdiary followupdiary){
        followupdiary.setReturnVisit("华佗");
        int i = followupdiaryService.insertSelective(followupdiary);
        return i;
    }
}
